$(()=>{
    if(sessionStorage.getItem("msg_data")==null){
        alert("您的登录信息已过期请重新登陆");
        window.location.href="http://172.18.80.9:8087/admin/login/login"
    }
    var setTotalCount = 301;
    $('#box').paging({
        initPageNo: 3, // 初始页码
        totalPages: 30, //总页数
        totalCount: '合计' + setTotalCount + '条数据', // 条目总数
        slideSpeed: 600, // 缓动速度。单位毫秒
        jump: true, //是否支持跳转
        callback: function(page) { // 回调函数
            console.log(page);
        }
    })
    //论文专利示范应用的跳转
    $(document).on("click",".l1",function () {
        window.location.href="http://172.18.80.9:8087/admin/research/thesislist"
    })
    $(document).on("click",".z1",function () {
        window.location.href="http://172.18.80.9:8087/admin/research/patentlist"
    })
    $(document).on("click",".s1",function () {
        window.location.href="http://172.18.80.9:8087/admin/research/demonstrationlist"
    })
    //session 的id和token
    var msg_data =JSON.parse(sessionStorage.getItem("msg_data"));
    console.log(msg_data.id)
    console.log(msg_data.token)
    // 示范应用条件搜索 列表
    var status = 1;
    $.ajax({
        type:"POST",
        dataType:"json",
        data:{uid:msg_data.id,token:msg_data.token,status:status},
        url:"http://172.18.80.9:8087/admin/research/searchPilot",
        success:function(data){
            console.log(data.data);
            if(data.code==9){
                alert(data.msg)
                window.location.href="http://172.18.80.9:8087/admin/login/login"
                return false;
            }
            var html=""
            for(var tmp of data.data){
                if(tmp.status==1){
                    html+=`
                 <tr>
                    <td>${tmp.project_name}</td>
                    <td>${tmp.pilot_name}</td>
                    <td>${tmp.place}</td>
                    <td>${tmp.pilot_date}</td>
                    <td>未提交</td>
                    <td>
                        <div class="btnn">
                            <a href="#" class="btn btn-info" style="background-color: #416aff;border-color:#416aff;"  id="editor" data-id="${tmp.id}">
                                <img src="../images/bianji.png">
                            </a>
                            <a href="">&nbsp;&nbsp;</a>
                            <a href="#" class="btn btn-info" style="background-color: #fe5722;border-color:#fe5722;" id="delect" data-id="${tmp.id}">
                                <img src="../images/delect.png">
                            </a>
                        </div>
                    </td>
                </tr>
             `
                }else if(tmp.status==2){
                    html+=`
                 <tr>
                    <td>${tmp.project_name}</td>
                    <td>${tmp.pilot_name}</td>
                    <td>${tmp.place}</td>
                    <td>${tmp.pilot_date}</td>
                    <td>已提交</td>
                    <td>
                        <div class="btnn2">
                            <a href="#" class="btn btn-info" style="background-color: #416aff;border-color:#416aff;" id="look" data-id="${tmp.id}">
                                <img src="../images/look.png">
                            </a>
                        </div>
                    </td>
                </tr>
             `
                }
            }
            $("#tbody1").html(html);
        },
        error:function(err){
            console.log(err);
            alert("网络故障请检查");
        }
    });
    $(document).on("change","#status",function () {
        var status = $(this).val();
        $.ajax({
            type:"POST",
            dataType:"json",
            data:{uid:msg_data.id,token:msg_data.token,status:status},
            url:"http://172.18.80.9:8087/admin/research/searchPilot",
            success:function(data){
                console.log(data.data);
                if(data.code==9){
                    alert(data.msg)
                    window.location.href="http://172.18.80.9:8087/admin/login/login"
                    return false;
                }
                var html=""
                for(var tmp of data.data){
                    if(tmp.status==1){
                        html+=`
                 <tr>
                    <td>${tmp.project_name}</td>
                    <td>${tmp.pilot_name}</td>
                    <td>${tmp.place}</td>
                    <td>${tmp.pilot_date}</td>
                    <td>未提交</td>
                    <td>
                        <div class="btnn">
                            <a href="#" class="btn btn-info" style="background-color: #416aff;border-color:#416aff;"  id="editor" data-id="${tmp.id}">
                                <img src="../images/bianji.png">
                            </a>
                            <a href="">&nbsp;&nbsp;</a>
                            <a href="#" class="btn btn-info" style="background-color: #fe5722;border-color:#fe5722;" id="delect" data-id="${tmp.id}">
                                <img src="../images/delect.png">
                            </a>
                        </div>
                    </td>
                </tr>
             `
                    }else if(tmp.status==2){
                        html+=`
                 <tr>
                    <td>${tmp.project_name}</td>
                    <td>${tmp.pilot_name}</td>
                    <td>${tmp.place}</td>
                    <td>${tmp.pilot_date}</td>
                    <td>已提交</td>
                    <td>
                        <div class="btnn2">
                            <a href="#" class="btn btn-info" style="background-color: #416aff;border-color:#416aff;" id="look" data-id="${tmp.id}">
                                <img src="../images/look.png">
                            </a>
                        </div>
                    </td>
                </tr>
             `
                    }
                }
                $("#tbody1").html(html);
            },
            error:function(err){
                console.log(err);
                alert("网络故障请检查");
            }
        });
    })
    //  添加
    $(document).on("click","#add1",function () {
        $.ajax({
            type:"POST",
            dataType:"json",
            data:{uid:msg_data.id,token:msg_data.token},
            url:"http://172.18.80.9:8087/admin/research/apPilot",
            success:function(data){
                if(data.data.code==9){
                    alert(data.data.msg)
                    return false;
                }
                window.location.href="http://172.18.80.9:8087/admin/research/adddemonstration?"+"add="+encodeURI(data.data);
            },
            error:function(err){
                console.log(err);
                alert("网络故障请检查");
            }
        });
    })
    //删除
    $(document).on("click","#delect",function (e) {
        e.preventDefault();
        var did =$(this).data("id");
        console.log(did);
        $.ajax({
            type: "POST",
            dataType:"json",
            data:{id:did,uid:msg_data.id,token:msg_data.token},
            url: "http://172.18.80.9:8087/admin/research/delpilot",
            success: function (data) {
                if(data.data.code==9){
                    alert(data.data.msg)
                    return false;
                }
                if(confirm("您确定要删除吗")){
                    alert("删除成功");
                    location.reload();
                }else{
                    return false;
                }
            },
            error: function (err) {
                console.log(err);
                alert("网络故障请检查");
            }
        });
    })
    //查看详情
    $(document).on("click","#look",function (e) {
        e.preventDefault();
        var tid =$(this).data("id");
        window.location.href="http://172.18.80.9:8087/admin/research/detaildemonstration?"+"id="+tid;
    })
    //编辑详情
    $(document).on("click","#editor",function (e) {
        e.preventDefault();
        var tid =$(this).data("id");
        window.location.href="http://172.18.80.9:8087/admin/research/adddemonstration?"+"id="+tid;
    })
})
